package fixtures;
import java.io.IOException;

import Library.Books;
import client.ClientConsole;
import GUI.GUI_LogIn;
import Library.Search;
import Server.EchoServer;
import fit.ActionFixture;

public class search extends ActionFixture {
	
	 GUI_LogIn cgui;
	 ClientConsole cc;
	 String UserName;
	 String Password;
	 String text;
	 String type;
	 EchoServer es;
	 public void connect(String ip)
	{
		//cgui=new GUI_LogIn();
		cc = new ClientConsole(ip);
		Thread t=new Thread(cc);
		t.start();
	}
	
	 public void server (){
	     es=new EchoServer(5555,"root","root");
			try {
				es.listen();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}	 
	}
	 
	 public void disserver()
	 {
		 
		 try {
			es.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	 }

		public void disconnect()
		{
		try {
			cc.client.closeConnection();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		}

		public void logout()
		{
			
			String[] s={"logout",UserName};
			try {
				cc.client.sendToServer(s);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			 

				while(cc.client.flag==0)
					System.out.print("");
				cc.client.flag=0;
				System.out.println("here");
				
		
			
			
			
		}
		
		
	
	public void UserName(String s)
	{
	UserName=s;
	}
	public void Password(String s)
	{
	Password=s;
	}
	
	public void login()
	{
		
		String s[]={"login",UserName,Password};
		try {
			cc.client.sendToServer(s);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 

			while(cc.client.flag==0)
				System.out.print("");
			cc.client.flag=0;
	}
	
	
	public void type(String type)
	{
	this.type=type;
	}
	
	
	public void text(String text)
	{
	this.text=text;
	}
	
	
	public int search()
	{
	
		
	String s[]={"search",text,type};
	  

	try {
		cc.client.sendToServer(s);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	 

		while(cc.client.flag==0)
			System.out.print("");
		cc.client.flag=0;
	   Search search =(Search)cc.client.message;
	   return (search.getBooksList().size());
	   
	
	}
	
	
	
	
	
	
	
	
}

